
from OpenGLContext import testingcontext
BaseContext = testingcontext.getInteractive()
from OpenGL.GL import *
from OpenGL.GLU import *

from BitmapMaterial import BitmapMaterial
from Plane import Plane
import time

from SceneNode import *
from SceneManager import *
from Camera import *


class TestContext(BaseContext):
    initialPosition = (0, 0, 0)
    
    def OnInit(self):
        matTwitter = BitmapMaterial()
        matTwitter.load('twitter.png')
        self.twitter = Plane(matTwitter, 256, 256, 4, 4)        
        self.twitterNode = SceneNode()
        self.twitterNode.setEntity(self.twitter)
        
        self.camera = Camera()
        self.camera.setPosition(0, 0, 500)
        self.camera.setUpVector(0,1,0)
        self.camera.lookAt(0, 0, 0)
        
        
        self.sceneMgr = SceneManager()
        self.sceneMgr.addSceneNode(self.twitterNode)
        self.sceneMgr.setCamera(self.camera)
        
        self.twitterNode.translateXYZ(0, 0, 0)
        
        
    def Render(self, mode):
        """Render scene geometry"""
        BaseContext.Render( self, mode )
        
        glClear(GL_COLOR_BUFFER_BIT)
        self.sceneMgr.renderScene()
        
        '''
        glDisable(GL_LIGHTING) # context lights by default
        
        glMatrixMode(GL_MODELVIEW)
        glLoadIdentity()
        gluLookAt(0,0,500,
                  0,0,0,
                  0,1,0)
        
        glClear(GL_COLOR_BUFFER_BIT)
        glFrontFace(GL_CW)        
        
        self.twitter.render()
        '''
        
        
    def OnIdle( self, ):
        """Request refresh of the context whenever idle"""
        self.triggerRedraw(1)
        return 1
    
    
        #glClear(GL_COLOR_BUFFER_BIT)
        #glFrontFace(GL_CW)
        
        
        '''
        glColor(0, 1, 0)        
        glBegin(GL_TRIANGLES)
        glVertex(-.25,-.25)
        glVertex(.25,-.25)
        glVertex(0, .25)
        glEnd()
        '''
        
        
        
        
if __name__ == "__main__":
    TestContext.ContextMainLoop()
    